package cn.com.winson.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.winson.springboot.config.MyConfig;

@Controller
public class IndexController {
	
	/*@Value注解将自定义配置引入到程序中*/
	@Value(value = "${winson.age}")
	private Integer age;
	
	@Value(value = "${winson.name}")
	private String name;
	
	@Autowired
	private MyConfig myConfig;
	
	/*添加@ResponseBody注解与返回值类型String组合使用，返回的是json字符串*/
	@GetMapping("/getInfo")
	@ResponseBody
	public String getInfo() {
		return "自定义属性的age为：" + age + "；name为：" + name + "。";
	}
	
	@GetMapping("/getInfo2")
	@ResponseBody
	public String getInfo2() {
		return "自定义属性的age为：" + myConfig.getAge() + "；name为：" + myConfig.getName() + "。";
	}

}
